home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11959 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: rain.fr!world-net!usenet
  2. From: Frederic LACHASSE <lachass@worldnet.fr>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Saving a file from C++ app to ANSI windows format.
  5. Date: Sun, 17 Mar 1996 07:35:16 +0000
  6. Organization: World-Net information exchange, Internet provider.
  7. Message-ID: <VA.0000006e.00028fb5@fred>
  8. References: <4ibc80$94o@mn5.swip.net>
  9. Reply-To: lachass@worldnet.fr
  10. NNTP-Posting-Host: client122.sct.fr
  11. X-Newsreader: Virtual Access by Ashmount Research Ltd, http://www.ashmount.com
  12.  
  13. In article <4ibc80$94o@mn5.swip.net>, m-27103@mailbox.swipnet.se (Walter 
  14. Lam) wrote:
  15. >
  16. > A fellow worker of mine asked me to post this question... I myself don't 
  17. > know much about it, so I hope someone on the Net does.....
  18. > How can I save a file from a C++ app as an ANSI Windows format?  The C++ 
  19. > app is a DOS app.
  20.  
  21. I suppose you want to translate some text from a DOS code page 437 (DOS US) 
  22. or 850 (DOS multinational) (or perhaps another more exotic) to the ISO8859 
  23. code page (I think it's 1004) used by Windows 3.x.
  24.  
  25. The simple way is by creating a conversion table. You can use half a table, 
  26. because the first 128 codes doesn't need to be translated.
  27.  
  28. Example of code:
  29.  
  30. char PC2ISO[128] = {
  31.   // here is the important work: find a PC437 or PC850 character set table
  32.   // and find the corresponding code in the ISO table.
  33.   
  34.   
  35. };
  36.  
  37. void translate(const char *from, size_t size, char *to)
  38. {
  39.   while (size)
  40.   {
  41.     *to = (char)((unsigned char)*from < 128 ? *from : PC2ISO[*from - 128]);
  42.     ++to;
  43.     ++from;
  44.     --size;
  45.   }
  46. }
  47.  
  48. I hope this'll help.
  49.  
  50.  Frederic LACHASSE (ECP 86)
  51.  CompuServe: 100530,2005
  52.  Internet: lachass@worldnet.fr
  53.  
  54.